<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>First jQuery page</title>
	</head>
	<body>
		<form id="commentForm">
			<label for="username">用户名：</label>
			<input id="username" type="text"/>
			<label for="comment">评论：</label>
			<input  id="comment" type="text"/>
			<input  id="submitBtn" type="button" value="提交"/>
		</form>
		<script type="text/javascript">
			$("#submitBtn").click(function(evt){
				evt.preventDefault();
				$.ajax("/api/add_comment",{
					type:"POST",
					data:{
						username:$("#username").val(),
					    comment:$("#comment").val()
					},
					success:function(result){
						var comments = JSON.parse(result);
						console.log(comments);
						console.log("提交成功");
					}
				})
				return false;
			})
		</script>
		<script src="js/jquery-3.6.1.js"></script>
	</body>
</html>
